from typing import Text, List, Any, Dict

from rasa_sdk import Tracker, FormValidationAction
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.types import DomainDict
from rasa_sdk import Action, Tracker


class ValidateOrderFoodForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_orderfood_form"

    @staticmethod
    def food_db() -> List[Text]:
        return ['鱼香肉丝', '宫保鸡丁', '蛋炒饭', '西红柿炒鸡蛋']

    def validate_food(
            self,
            slot_value: Any,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: DomainDict,
    ) -> Dict[Text, Any]:
        print('校验')
        if slot_value in self.food_db():
            return {"food": slot_value}
        else:
            return {"food": None}


class SubmitOrders(Action):
    def name(self) -> Text:
        return 'action_submit_food'

    def run(
            self,
            dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]
    ) -> List[Dict[Text, Any]]:
        print("************")
        print(tracker.slots)
        dispatcher.utter_message('已为您订餐')
        return []
